package start.spring.basic.report.service.filltemplete.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Service;

import start.spring.basic.report.service.BaseServiceImpl;
import start.spring.basic.report.service.filltemplete.ISysPluginService;
import start.spring.basic.report.vo.filltemplete.ColumnInfo;
import start.spring.basic.report.vo.filltemplete.TableInfo;
import start.spring.basic.response.ResponseData;

/**
 * 
 * ****************************************************************************
 * 系统插件业务接口实现
 *
 * @author(作者)：xuyongyun	
 * @date(创建日期)：2024年1月8日
 ******************************************************************************
 */
@Service
public class SysPluginServiceImpl extends BaseServiceImpl implements ISysPluginService {

	@Override
	public ResponseData<List<TableInfo>> queryDbtree() {
		List<TableInfo> tableList = new ArrayList<>();
		//查询表信息sql
		String sqlTableInfo = "SELECT table_schema as tableSchema, table_name as tableName, table_comment as tableComment FROM information_schema.tables WHERE table_name LIKE 'report_%' AND table_schema NOT IN('sys','mysql','information_schema','performance_schema')";
		//查询表字段sql
		String sqlColumnInfo = "SELECT column_name as columnName,column_comment as columnComment,column_type as columnType FROM information_schema.columns WHERE table_schema NOT IN('sys','mysql','information_schema','performance_schema') AND table_name = ? ORDER BY ordinal_position";
		tableList = super.dynamicJdbc.query(null, sqlTableInfo, null, TableInfo.class);
		if(tableList!=null) {
			for(TableInfo tableInfo:tableList) {
				List<ColumnInfo> columnList = super.dynamicJdbc.query(null, sqlColumnInfo, new String[] {tableInfo.getTableName()}, ColumnInfo.class);
				tableInfo.setColumnList(columnList);
			}
		}
		return ResponseData.successData(tableList);
	}

}
